idxHC = -1;
// Headless client check
waitUntil{!isNil "headlessClients"};

if (!isDedicated) then {
	private["_hc"];
	if (!isDedicated && !hasInterface) then {
		// Random delay
		for [{_x=1},{_x<=random 5000},{_x=_x+1}] do {};
		idxHC = headlessClients find player;
		if(idxHC < 0) then {
			idxHC = count headlessClients;
			headlessClients set [idxHC, player];
			publicVariable "headlessClients";
			player addEventHandler["killed",{
				waituntil {!(isNull player) && player == player};
				headlessClients set [idxHC, player];
				for [{_x=1},{_x<=random 10000},{_x=_x+1}] do {};
				publicVariable "headlessClients";
			}];
		};
	};
};